$(function(){
		$("#sectionTable").datagrid({
			pagination:true,
			idField:"id"
		})
	})
	//添加科室
	function add_section(){
		addDialog("添加科室",400,200,"section/form","#sectionForm","section/insert","#sectionTable");
	}

	//修改科室
	function edit_section(){
		var row = $("#sectionTable").datagrid("getSelected");
		if(row == null){
			$.messager.alert("提示","请选中要修改的数据行！","warning");
			return;
		}

		//如果选中了多个，只保留row这个
		$("#sectionTable").datagrid("clearSelections");
		$("#sectionTable").datagrid("selectRecord",row.id);
		
		var d = $("<div></div>").appendTo("body");
		d.dialog({
			title : "修改科室",
			iconCls : "icon-edit",
			width:400,
			height:200,
			modal:true,
			href : "section/form",
			onClose:function(){$(this).dialog("destroy"); },
			onLoad:function(){
				//发送异步请求，查询数据
				$.post("section/sid",{id:row.id},function(data){
					$("#sectionForm").form("load",data);
				});
			},
			buttons:[{
				iconCls:"icon-ok",
				text:"确定",
				handler:function(){
					$("#sectionForm").form("submit",{
						url : "section/edit",
						success : function(data){
							d.dialog("close");
							$("#sectionTable").datagrid("reload");
						}
					});
				}
			},{
				iconCls:"icon-cancel",
				text:"取消",
				handler:function(){
					d.dialog("close");
				}
			}]
		})
	}
	
	//删除科室
	function delete_section(){
		deleteConfirm("#sectionTable","section/editstate");
	}